package com.project.xsf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.common.entity.PageVo;
import com.project.common.utils.Serial;
import com.project.xsf.entity.MDesignProcedureModule;
import com.project.xsf.entity.MManufacture;
import com.project.xsf.mapper.MManufactureMapper;
import com.project.xsf.service.MManufactureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class MManufactureImpl implements MManufactureService {
    @Autowired
    private MManufactureMapper mManufactureMapper;
    @Override
    public int insertSelective(MManufacture record) throws IOException {
        record.setCheckTag("S001-0");
        record.setManufactureProcedureTag("S002-0");
        Serial serial = new Serial();
        serial.addUser("manufactureId","301");
        String manufactureId = serial.getNumber("manufactureId", "301", null, null, null);
        record.setManufactureId(manufactureId);
        return mManufactureMapper.insertSelective(record);
    }

    @Override
    public PageVo<MManufacture> queryMManufactureNoCheck(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));
//        System.out.println(map);
        PageHelper.startPage(pageNum,pageSize);
        List<MManufacture> mManufactures = mManufactureMapper.queryMManufactureNoCheck();

        PageInfo<MManufacture> pageInfo = new PageInfo<MManufacture>(mManufactures);

        PageVo<MManufacture> pageVo = new PageVo<MManufacture>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }

    @Override
    public PageVo<MManufacture> queryAllMManufacture(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));
//        System.out.println(map);
        PageHelper.startPage(pageNum,pageSize);
        List<MManufacture> mManufactures = mManufactureMapper.queryAllMManufacture();

        PageInfo<MManufacture> pageInfo = new PageInfo<MManufacture>(mManufactures);

        PageVo<MManufacture> pageVo = new PageVo<MManufacture>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }

    @Override
    public int updateByPrimaryKeySelective(MManufacture record) {
        return mManufactureMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public MManufacture selectByPrimaryKey(Integer id) {
        return mManufactureMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageVo<MManufacture> queryMManufactureCheckAndNoProcedure(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));
//        System.out.println(map);
        PageHelper.startPage(pageNum,pageSize);
        List<MManufacture> mManufactures = mManufactureMapper.queryMManufactureCheckAndNoProcedure();

        PageInfo<MManufacture> pageInfo = new PageInfo<MManufacture>(mManufactures);

        PageVo<MManufacture> pageVo = new PageVo<MManufacture>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }

    @Override
    public PageVo<MManufacture> queryMManufactureNoReCheck(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));
//        System.out.println(map);
        PageHelper.startPage(pageNum,pageSize);
        List<MManufacture> mManufactures = mManufactureMapper.queryMManufactureNoReCheck();

        PageInfo<MManufacture> pageInfo = new PageInfo<MManufacture>(mManufactures);

        PageVo<MManufacture> pageVo = new PageVo<MManufacture>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }

    @Override
    public PageVo<MManufacture> queryMManufacture(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));
//        System.out.println(map);
        PageHelper.startPage(pageNum,pageSize);
        List<MManufacture> mManufactures = mManufactureMapper.queryMManufacture();

        PageInfo<MManufacture> pageInfo = new PageInfo<MManufacture>(mManufactures);

        PageVo<MManufacture> pageVo = new PageVo<MManufacture>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }
}
